package com.think.teaching.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.think.teaching.mapper.TrainingTagMapper;
import com.think.teaching.model.TrainingTag;
import com.think.teaching.service.TrainingTagService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 实训标签 服务实现类
 * </p>
 *
 * @author think
 * @since 2020-08-12
 */
@Service
public class TrainingTagServiceImpl extends BaseServiceImpl<TrainingTagMapper, TrainingTag> implements TrainingTagService {

	@Override
	public TrainingTag AddTrainingTag(TrainingTag result) {
		if (this.save(result)) {
			return result;
		}
		return null;
	}

	@Override
	public TrainingTag UpdateTrainingTag(TrainingTag result) {
		if (this.updateById(result)) {
			return result;
		}
		return null;
	}

	@Override
	public TrainingTag GetTrainingTag(Integer id) {
		QueryWrapper<TrainingTag> queryWrapper = new QueryWrapper<>();
		queryWrapper.eq("id", id).eq("state", 1).ne("delflag", 1);
		return getOne(queryWrapper);
	}

	@Override
	public IPage<TrainingTag> ListTrainingTag(Integer page, Integer count, Boolean withoutBan) {
		QueryWrapper<TrainingTag> queryWrapper = new QueryWrapper<>();
		queryWrapper.ne("delflag", 1);
		if (withoutBan) {
			queryWrapper.eq("state", 1);
		}
		IPage<TrainingTag> ipage = new Page<>(page, count);
		return this.page(ipage);
	}

	@Override
	public TrainingTag SetTrainingTagState(Integer id, Integer state) {
		UpdateWrapper<TrainingTag> queryWrapper = new UpdateWrapper<>();
		queryWrapper.eq("id", id).ne("delflag", 1).set("state", state);
		this.update(queryWrapper);
		return getById(id);
	}

}
